package com.hnrd.crud.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hnrd.crud.annotation.Permissions;
import com.hnrd.crud.pojo.Permission;
import com.hnrd.crud.service.PermissionService;

@RequestMapping("permissions")
@RestController
public class PermissionController {
	@Autowired
	private PermissionService permissionService;
	
	@Permissions(permission="管理员")
	@PostMapping("addPermission")
	public ResponseEntity<Map<String,Object>> addPermission(@RequestBody Permission permission){//添加新权限
		return permissionService.insert(permission);
	}
	@Permissions(permission="管理员")
	@PutMapping("deletePermission")
	public ResponseEntity<Map<String, Object>> deletePermission(Integer permissionId){//删除权限
		return permissionService.delete(permissionId);
	}
	@Permissions(permission="管理员")
	@RequestMapping("updatePermisson")
	public ResponseEntity<Map<String,Object>> updatePermission(Permission permission){//修改权限名称
		return permissionService.update(permission);
	}
	@Permissions(permission="管理员")
	@RequestMapping("selectPermissions")
	public ResponseEntity<Map<String, Object>> selectPermissions(){
		return permissionService.selectPermissions();
	}
}
